home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / sbprocss / sbsample.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-09-20  |  2.7 KB  |  77 lines

  1. unit SBSample;
  2.     interface
  3.         function ResetDSP: boolean;
  4.         procedure TurnSpeakerOn;
  5.         procedure TurnSpeakerOff;
  6.         function GetSample: byte;
  7.         procedure OutputSample(Sample: byte);
  8.     implementation
  9.         uses
  10.             CRT;
  11.         const
  12.             ResetPort    = $226;
  13.             ReadPort     = $22A;
  14.             WritePort    = $22C;
  15.             PollPort     = $22E;
  16.  
  17.             CmdDirectDAC    = $10;
  18.             CmdDirectADC    = $20;
  19.             CmdSpeakerOn    = $D1;
  20.             CmdSpeakerOff   = $D3;
  21.         procedure WriteDSP(Value: byte);
  22.             Inline
  23.               (
  24.                 $BA/>WritePort/        {MOV   DX, WritePort (Constant)  }
  25.                 $EC/                   {IN    AL, DX                    }
  26.                 $24/$80/               {AND   AL, 80h                   }
  27.                 $75/$FB/               {JNZ   -05                       }
  28.                 $58/                   {POP   AX                        }
  29.                 $BA/>WritePort/        {MOV   DX, WritePort (Constant)  }
  30.                 $EE                    {OUT   DX, AL                    }
  31.               );
  32.         function ReadDSP: byte;
  33.             Inline
  34.               (
  35.                 $BA/>PollPort/         {MOV   DX, PollPort  (Constant)  }
  36.                 $EC/                   {IN    AL, DX                    }
  37.                 $24/$80/               {AND   AL, 80h                   }
  38.                 $74/$FB/               {JZ    -05                       }
  39.                 $BA/>ReadPort/         {MOV   DX, ReadPort  (Constant)  }
  40.                 $EC                    {IN    AL,DX                     }
  41.               );
  42.         function ResetDSP: boolean;
  43.             var
  44.                 i: byte;
  45.             begin
  46.                 Port[ResetPort] := 1;
  47.                 Delay(1);
  48.                 Port[ResetPort] := 0;
  49.                 i := 0;
  50.                 repeat
  51.                     Inc(i);
  52.                 until (ReadDSP = $AA) or (i = 100);
  53.                 if i < 100
  54.                     then ResetDSP := true
  55.                     else ResetDSP := false;
  56.             end;
  57.         procedure TurnSpeakerOn;
  58.             begin
  59.                 WriteDSP(CmdSpeakerOn);
  60.             end;
  61.         procedure TurnSpeakerOff;
  62.             begin
  63.                 WriteDSP(CmdSpeakerOff);
  64.             end;
  65.         function GetSample: byte;
  66.             begin
  67.                 WriteDSP(CmdDirectADC);
  68.                 GetSample := ReadDSP;
  69.             end;
  70.         procedure OutputSample(Sample: byte);
  71.             begin
  72.                 WriteDSP(CmdDirectDAC);
  73.                 WriteDSP(Sample);
  74.             end;
  75.     begin
  76.     end.
  77.